Ext.ns("ProjectTree");
/**
 * 项目数列表
 * @param {} options
 */
var ProjectTree = function(options) {
	if (!options) {
		options = {}
	};
	if (!options.id) {
		alert("没有id");
		return;
	};
	//    if(!options.title){alert("没有title");return;};
	if (!options.url) {
		alert("没有url");
		return;
	}
	if (!options.click) {
		alert("没有click");
		return;
	};

	var comboGlobalType = new Ext.form.ComboBox({
				editable : false,
				hiddenName : "comboGlobalTypeValue",
				displayField : !options.comFields ? "" : options.comFields[1],
				valueField : !options.comFields ? "" : options.comFields[0],
				mode : "local",
				triggerAction : "all",
				store : new Ext.data.ArrayStore({
                        fields : !options.comFields ? [] : options.comFields,
                        data : !options.comData ? [] : options.comData
                }),
                value : "0", 
				listeners : {
					 "select" : function(combo, record, index){
					 	treePanel.loader.dataUrl = __ctxPath + (options.url).split('?')[0] + "?"+options.comFields[0] 
                                                            + "=" + record.json[0];
                        treePanel.root.reload();                                    
					 }
				}
			});

	var topLeftPanel = new Ext.Panel({
				layout : "fit",
				region : "north",
				border : false,
				height : 23,
				items : [comboGlobalType]
			});

	var treePanel = new Ext.tree.TreePanel({
				id : options.id,
				layout : "fit",
				region : "center",
				split : true,
				//        collapsible : true,
				autoScroll : true,
				height : 800,
				width : 180,
				tbar : new Ext.Toolbar({
							items : [{
										xtype : "button",
										iconCls : "btn-refresh",
										text : "刷新",
										handler : function() {
											treePanel.root.reload();
										}
									}, "-", {
										xtype : "button",
										text : "展开",
										iconCls : "btn-expand",
										handler : function() {
											treePanel.expandAll();
										}
									}, "-", {
										xtype : "button",
										text : "收起",
										iconCls : "btn-collapse",
										handler : function() {
											treePanel.collapseAll();
										}
									}]
						}),
				loader : new Ext.tree.TreeLoader({
							url : __ctxPath + options.url
						}),
				root : new Ext.tree.AsyncTreeNode({
							expanded : true
						}),
				rootVisible : false,
				listeners : {
					"click" : options.click
				}
			});

	var tree = new Ext.Panel({
				region : options.region == null
						|| options.region == 'undefined'
						? "west"
						: options.region,
				title : options.title == null || options.title == 'undefined'
						? "零件信息列表"
						: options.title,
				layout : "border",
				//                    collapsible : true,
				split : true,
				width : 200,
				items : [ treePanel]
			});
			
    if(options.treeSearch){
        tree.add(topLeftPanel);
    }
    
	return tree;
};
